﻿using GlennQuigmire.API.Application.Commands;
using IMES.Common.Domain.SirModel;
using IMES.Common.Dtos;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace GlennQuigmire.API.Controllers
{
    /// <summary>
    /// 产品控制器--API
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductsController : ControllerBase
    {

        private readonly IMediator mediator;

        public ProductsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加产品信息
        /// </summary>
        /// <param name="cmd">添加产品信息请求对象</param>
        /// <returns>添加产品信息响应对象</returns>
        [HttpPost]
        public Task<Result> ProductCreate(ProductCreateCommand cmd)
        {
            return mediator.Send(cmd);
        }


        /// <summary>
        /// 产品信息查询显示
        /// </summary>
        /// <param name="cmd">产品信息查询显示请求对象</param>
        /// <returns>产品信息查询显示响应对象</returns>
        [HttpPost]
        public Task<ResultPage<Product>> Handle(ProductSearchCommand cmd)
        {
            return mediator.Send(cmd);
        }

        /// <summary>
        /// Get方法查询产品信息
        /// </summary>
        /// <param name="cmd">查询产品信息请求对象</param>
        /// <returns>查询产品信息响应对象</returns>
        [HttpGet]
        public Task<ResultPage<Product>> GetSearchProducts([FromQuery]ProductSearchGetCommand cmd)
        {
            return mediator.Send(cmd);
        }




    }
}
